package com.mfcxy.entity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.multipart.MultipartFile;

import com.mfcxy.exception.CustomException;
/**
 * 
 * @author mfcxy
 *
 */
public class Blog {
	private int id;
	private String title;
	private int tid;
	private String tname;
	private int uid;
	private String nickname;
	private String image;
	private String label;
	private String describe;
	private String content;
	private String isshow;
	private String isdel;
	private int readingnum;
	private int style;
	private String createtime;
	private String updatetime;

	// 上传图片对象
	private List<MultipartFile> images;
	//图片的url （json字符串转换过来的）
	private List<String> imageUrl;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getTid() {
		return tid;
	}

	public void setTid(int tid) {
		this.tid = tid;
	}

	public String getTname() {
		return tname;
	}

	public void setTname(String tname) {
		this.tname = tname;
	}

	public int getUid() {
		return uid;
	}

	public void setUid(int uid) {
		this.uid = uid;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getDescribe() {
		return describe;
	}

	public void setDescribe(String describe) {
		this.describe = describe;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getIsshow() {
		return isshow;
	}

	public void setIsshow(String isshow) {
		this.isshow = isshow;
	}

	public String getIsdel() {
		return isdel;
	}

	public void setIsdel(String isdel) {
		this.isdel = isdel;
	}

	public int getReadingnum() {
		return readingnum;
	}

	public void setReadingnum(int readingnum) {
		this.readingnum = readingnum;
	}

	public int getStyle() {
		return style;
	}

	public void setStyle(int style) {
		this.style = style;
	}

	public String getCreatetime() {
		return createtime;
	}

	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}

	public String getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(String updatetime) {
		this.updatetime = updatetime;
	}

	public List<MultipartFile> getImages() {
		return images;
	}

	public void setImages(List<MultipartFile> images) {
		this.images = images;
	}
	
	/**
	 *  新增验证
	 * @throws CustomException
	 */
	public void checkAdd() throws CustomException {
		
		List<String> listmsg = new ArrayList<>();
		
		if(title != null) {
			title = title.trim();
			if(title.equals("")) {
				listmsg.add("标题不能为空");
			}
		} else {
			listmsg.add("标题不能为空");
		}
		
		if(tid == 0) {
			listmsg.add("分类未选择");
		}
		
		if(tname != null) {
			tname = tname.trim();
			if(tname.equals("")) {
				listmsg.add("分类名称不能为空");
			}
		} else {
			listmsg.add("分类名称不能为空");
		}
		
		if(describe != null) {
			describe = describe.trim();
			if(describe.equals("")) {
				listmsg.add("描述不能为空");
			}
		} else {
			listmsg.add("描述不能为空");
		}
		
		if(content != null) {
			content = content.trim();
			if(content.equals("")) {
				listmsg.add("正文不能为空");
			}
		} else {
			listmsg.add("正文不能为空");
		}
		
		if(images == null || images.size() == 0) {
			listmsg.add("封面未上传");
		} else if(images.size() > 6) {
			listmsg.add("封面不能多余6张");
		}
		
		if(listmsg.size() > 0) {
			throw new CustomException(listmsg.toString());
		}
		
	}

	public List<String> getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(List<String> imageUrl) {
		this.imageUrl = imageUrl;
	}

	@Override
	public String toString() {
		return "Blog [id=" + id + ", title=" + title + ", tid=" + tid + ", tname=" + tname + ", uid=" + uid
				+ ", nickname=" + nickname + ", image=" + image + ", label=" + label + ", describe=" + describe
				+ ", content=" + content + ", isshow=" + isshow + ", isdel=" + isdel + ", readingnum=" + readingnum
				+ ", style=" + style + ", createtime=" + createtime + ", updatetime=" + updatetime + ", images="
				+ images + ", imageUrl=" + imageUrl + "]";
	}

}
